package com.dou.yygh.user.controller.api;

import com.dou.yygh.common.result.Result;
import com.dou.yygh.common.utils.AuthContextHolder;
import com.dou.yygh.model.user.Patient;
import com.dou.yygh.user.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created with IntelliJ IDEA 2021.1 x64
 *
 * @Author: 窦义超
 * @Date: 2021/11/2021/11/9/23:35
 * @Description:
 */
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {

    @Autowired
    private PatientService patientService;

    //获取就诊人的列表
    @GetMapping("auth/findAll")
    public Result findAll(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> list = patientService.findAllUserId(userId);

        return Result.ok(list);
    }
    //添加就诊人
    @PostMapping("auth/save")
    public Result savePatient(@RequestBody Patient patient,HttpServletRequest request){
        //获取当前登录的Id
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }
    //根据id获取就诊人的信息
    @GetMapping("auth/get/{id}")
    public Result getPatient(@PathVariable long id){
      Patient patient=  patientService.getPatientId(id);
      return Result.ok(patient);
    }
    //修改就诊人
    @PostMapping("auth/update")
    public Result updatePatient(@RequestBody Patient patient){
        patientService.updateById(patient);
        return Result.ok();
    }
    //删除就诊人
@DeleteMapping("auth/remove/{id}")
public Result removePatient(@PathVariable long id){
    boolean patient=  patientService.removeById(id);
    return Result.ok();
}

//根据就诊人id获取信息
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(@PathVariable long id){
        Patient patientId = patientService.getPatientId(id);
        return patientId;
    }
}
